package com.yuezhi.consumer.config.Publish_Subscribe;

import com.yuezhi.consumer.constant.QueueConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 发布订阅模式
 * Direct交换机配置
 */
@Configuration
public class RabbitDirectConfig {

    @Bean
    Queue direct() {
        return new Queue(QueueConstant.DIRECT_QUEUE);
    }

    @Bean
    DirectExchange directExchange() {
        return new DirectExchange(QueueConstant.DIRECT_EXCHANGE, true, false);
    }

    @Bean
    Binding binding() {
        return BindingBuilder.bind(direct())
                .to(directExchange()).with("direct");
    }
}
